package com.bridgeintelligent.tag.customer.mapper;

import com.bridgeintelligent.tag.customer.entity.IssueLog;
import com.bridgeintelligent.tag.customer.entity.IssueTask;
import com.bridgeintelligent.tag.customer.model.IssueTaskQueryModel;
import com.bridgeintelligent.tag.customer.vo.IssueTaskVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * @description
 * @author: grp 2021-02-23 14:49
 **/
@Mapper
public interface IssueTaskMapper {
    int add(IssueTask issue);

    List<IssueTaskVO> findList(IssueTaskQueryModel model);

    int update(IssueTask issueTask);

    @Delete("delete from TAG_CUSTOMERS_ISSUE_TASK where id = #{id}")
    int deleteById(String id);

    IssueTaskVO findOne(String id);

    @Select("select count(1) from TAG_CUSTOMERS_ISSUE_TASK where issue_name = #{name} and is_del = '00'")
    int countByName(String name);

    @Select("select count(1) from TAG_CUSTOMERS_ISSUE_TASK where issue_key = #{id} and is_del = '00'")
    int countById(String id);

    @Select("select count(1) from TAG_CUSTOMERS_ISSUE_TASK where issue_name = #{name} and issue_key <> #{id} and is_del = '00'")
    int countByNameAndNotId(String name, String id);

    List<IssueTask> findValidTasks(String date);

    @Select("select b.id,b.data_date,c.frequency  from TAG_CUSTOMERS_ISSUE_PENDING a left join TAG_CUSTOMERS_ISSUE_LOG_INFO b on a.log_id = b.id " +
            " left join TAG_CUSTOMERS_ISSUE_TASK_LOG c on b.id = c.id  where b.STATE = '0'")
    List<IssueLog> findPending();

    int updateToStop(String date, Date updateTime);

    @Select("select count(1) from ES_TIME_DATA where time = #{dataDate} and index_id = #{indexId}")
    int countEs6(String dataDate,String indexId);

    @Select("select count(1) from ES_TIME_DATA where time = #{dataDate} and index_id = #{indexId}")
    int countEs8(String dataDate,String indexId);

    @Select("select count(1) from TAG_CUSTOMERS_ISSUE_PENDING where id = #{id}")
    int countPending(String id);

    int countStartAndEnd(String id, String dataDate);

    int updateToStopTask(String date, Date updateTime);

    int updateCustomersToStopTask(Date updateTime);

    int updateCustomersToStop(Date updateTime);

    int immediateCheckCount(String id);

    String indexLastTime(String indexId);

    int updateTaskLog(IssueTask issueTask);

    List<String> findLogByIssueId(String issueId);

}
